package com.my.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.my.bean.*;
import com.my.service.WorkArrangementService;
import com.my.service.WorkguidaceService;
import com.my.util.SessionUtil;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 闫亚茹
 * @since 2018-08-25
 */
@Controller
@RequestMapping("/workArrangement")
public class WorkArrangementController {
	@Autowired
    WorkArrangementService workArrangementService;
    Logger logger=Logger.getLogger(WorkguidaceController.class);

    /**
     * 添加
     * @param
     * @return
     */
	@RequestMapping("/addworkArrangement")
	@ResponseBody
    public String addworkArrangement(String param,HttpSession session){
        WorkArrangement workArrangement= JSON.parseObject(param,WorkArrangement.class);
        workArrangement.setIsDelete(2);
        workArrangement.setCreatetime(new Date().getTime());
        Long areaid=((User)session.getAttribute("user")).getAreaId();
        workArrangement.setAreaid(areaid);
	    if (workArrangementService.insert(workArrangement)){
            logger.info("{addworkArrangement|保存成功}");
            return "保存成功";
        }else {
            logger.info("{addworkArrangement|添加失败}");
            return "添加失败";
        }
    }

    /**
     * 查询
     * @param voPage
     * @return
     */
    @RequestMapping("/selectWorkArrangement")
    @ResponseBody
    public ResultPage<WorkArrangement> selectWorkArrangement(String lin, String data, VoPage voPage, HttpSession session ){

        boolean admin=false;
//如果事超级管理员  即可查看所有的房间  判断是否为超级管理员
        if(SessionUtil.getSessionUser(session).getRoles().getRoleValue().equals("9f77d5a8-75c6-4d06-adf9-a37e727d491a")){
            admin=true;
        }

        Map map=new HashMap();
        map.put("lin",lin);
        map.put("data",data);
        Long areaid=((User)session.getAttribute("user")).getAreaId();
        ResultPage<WorkArrangement> resultPage = workArrangementService.selectMyPage(map,voPage,areaid,admin);
         return resultPage;
    }

    /**
     * 护理日常工作安排
     * @return
     */
    @RequestMapping("/workArran")
    public String Workguidace (){
        return "day_nursing";
    }


    /**
     * 删除护理日常工作安排
     * @param id
     * @return
     */
    @RequestMapping("/deleteWorkArrangement")
    @ResponseBody
    public boolean deleteWorkArrangement(Long id){
        return workArrangementService.deleteById(id);
    }

    /**
     * 修改护理日常工作安排
     * @param
     * @return
     */
    @RequestMapping("/updateWorkArrangement")
    @ResponseBody
    public String updateWorkArrangement(String param){
        List<WorkArrangement> list = new ArrayList<>();
        WorkArrangement workArrangement=JSONObject.parseObject(param,WorkArrangement.class);
        list.add(workArrangement);
        if(workArrangementService.updateBatchById(list)){
            return "修改成功";
        }else{
            return "修改失败";
        }
    }

    @RequestMapping("workarr_Add")
    public String  workarr(){
        return "/Alert/workarr_Add";
    }
    @RequestMapping("workarr_edit")
    public String  workarredit(){
        return "/Alert/workarr_edit";
    }


}
